package com.vancouver.knows.business.tracker;

import com.pangu.service.ActionException;
import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.Constants;
import com.vancouver.knows.business.bean.SplashAdInfo;
import com.vancouver.knows.business.bean.VersionInfo;

/**
 * 获取版本更新列表
 *
 * @author llf
 *
 */
public class SplashAdInfoTracker extends ABInvokeTracker {

	public SplashAdInfoTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	public String TAG() {
		return SplashAdInfoTracker.class.getSimpleName();
	}

	@Override
	public void handleResult(OperateResult result) {

		saveSplashAdInfo(result);
	}

	private void saveSplashAdInfo(OperateResult result) {
		SplashAdInfo splashAdInfo = (SplashAdInfo) result.getResultData();
		if (splashAdInfo == null) return;
		module.getCacheManager().setSplashAdInfoCache(splashAdInfo);
		imContext.handleMobEmptyMessage(Constants.BUSINESS_STATUS_SHOW_SPLASH_AD);
	}

	@Override
	public void handleFault(OperateResult result) {
		ActionException actionException = result.getActionException();
		if (actionException.getExCode() != 0) {
			SplashAdInfo splashAdInfo = new SplashAdInfo();
			splashAdInfo.setTimeLength("4");
			splashAdInfo.setRedirUrl(null);
			splashAdInfo.setImageUrl(null);
			splashAdInfo.setErrorCode(String.valueOf(actionException.getExCode()) );
			module.getCacheManager().setSplashAdInfoCache(splashAdInfo);
		}
	}

}
